'''
Created on Aug 9, 2012

@author: agaliull
'''
import os

algorithms = ["V_", "J_", "P_"]
path_exp = "C:/Dropbox/Research/Thesis/Report1/Experiments/results/"

def scale():
    path = path_exp + "scale/"
    
    sizes = ["1000", "5000", "10000", "20000", "30000", "40000", "50000"]

    f_out = open(path + "results.csv", 'w') 
    #f_out.write("#tuples,vldb,journal,pceps\n")
    
    for size in sizes:
        f_out.write(size + ",")
        
        for alg in algorithms:
            filepath = path + alg + size;
    
            if not os.path.exists(filepath):
                f_out.write(",")
            else:
                f_in = open(filepath, 'r')
                lines = f_in.readlines()
                
                time_sum = 0.0
                for line in lines:
                    time_sum += float(line.split(",")[1])
                
                f_out.write("{0:.3f},".format(time_sum/len(lines)))
                
            f_in.close()
            
        f_out.write("\n")
            
    f_out.close()
    
def perturbation():
    path = path_exp + "perturbation/"
    
    errors = ['0', '5', '10', '15', '20', '25', '30']

    f_out = open(path + "results.csv", 'w') 
    #f_out.write("#tuples,vldb,journal,pceps\n")
    
    for error in errors:
        f_out.write(error + ",")
        
        for alg in algorithms:
            filepath = path + alg + error;
    
            if not os.path.exists(filepath):
                f_out.write(",")
            else:
                f_in = open(filepath, 'r')
                lines = f_in.readlines()
                
                time_sum = 0.0
                for line in lines:
                    time_sum += float(line.split(",")[1])
                
                f_out.write("{0:.3f},".format(time_sum/len(lines)))
                
            f_in.close()
            
        f_out.write("\n")
            
    f_out.close()
    
scale()
perturbation()